
public class BoardCell {

	private int file, rank;
	private Piece piece;
	
	public BoardCell(int file, int rank) {
		if(file < 1 || file > 8 || rank < 1 || rank > 8){
			throw new RuntimeException("BoardCell with file = " + file + " and rank = " + rank + " cannot be created.");
		}
		setFile(file);
		setRank(rank);
	}
	
	public int getFile() {
		return file;
	}
	
	public void setFile(int file) {
		this.file = file;
	}
	
	public int getRank() {
		return rank;
	}
	
	public void setRank(int rank) {
		this.rank = rank;
	}
	
	public void setPiece(Piece piece) {
		this.piece = piece;
	}
	
	public Piece getPiece() {
		return piece;
	}

	public int getFileDifference(BoardCell other) {
		return getFile() - other.getFile();
	}
	
	public int getFileDifference(int file) {
		return getFile() - file;
	}
	
	public int getRankDifference(BoardCell other) {
		return getRank() - other.getRank();
	}
	
	public int getRankDifference(int rank) {
		return getRank() - rank;
	}
	
	public boolean isSameFile(BoardCell other) {
		return getFileDifference(other) == 0;
	}

	public boolean isSameRank(BoardCell other) {
		return getRankDifference(other) == 0;
	}	

	public boolean isInDiagonalWith(BoardCell other) {
		return Math.abs(getFileDifference(other)) == 
				Math.abs(getRankDifference(other));
	}

	@Override
	public String toString() {
		return new String(getFile() + "-" + getRank());
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null || !(obj instanceof BoardCell)) {
			return false;
		}

		BoardCell otherCell = (BoardCell) obj;
		if (toString().equals(otherCell.toString())) {
			return true;
		} else return false;
	}
	
	@Override
	public int hashCode() {
		return this.toString().hashCode();
	}

}
